// dnSpy decompiler from Assembly-CSharp.dll class: MathUtils
using System;
using System.Collections.Generic;
using UnityEngine;

public static class MathUtils
{
	public static void NormalizeProbabilities(float[] probabilities)
	{
		float num = 0f;
		foreach (float num2 in probabilities)
		{
			num += num2;
		}
		if (num == 0f)
		{
			return;
		}
		if (num == 1f)
		{
			return;
		}
		for (int j = 0; j < probabilities.Length; j++)
		{
			probabilities[j] /= num;
		}
	}

	public static int GetRandomIntFromDistribution(float[] density)
	{
		float num = UnityEngine.Random.Range(0f, 1f);
		int i;
		for (i = 0; i < density.Length; i++)
		{
			if (num < density[i])
			{
				break;
			}
			num -= density[i];
		}
		if (i == density.Length)
		{
			return -1;
		}
		return i;
	}

	public static byte[] GetRandomByteArray(int size, byte maxValue)
	{
		byte[] array = new byte[size];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = (byte)UnityEngine.Random.Range(0, (int)maxValue);
		}
		return array;
	}

	public static byte RotateBitset6Left(byte bitset6, int shift)
	{
		if (shift < 0)
		{
			UnityEngine.Debug.LogError("shift must be >= 0! current value: " + shift);
		}
		shift %= 6;
		int num = shift;
		int num2 = 6 - shift;
		int num3 = (int)bitset6 & (1 << num2) - 1;
		int num4 = ((int)bitset6 & (1 << num) - 1 << num2) >> num2;
		return (byte)(num4 | num3 << shift);
	}

	public static float DistanceSqIgnoreY(Vector3 point1, Vector3 point2)
	{
		Vector3 vector = point1 - point2;
		vector.y = 0f;
		return vector.sqrMagnitude;
	}

	public static int[] GetRandomSubsetFromNOfSize(int n, int subsetSize, MathUtils.IsValueAllowed isValueAllowed)
	{
		if (subsetSize > n)
		{
			UnityEngine.Debug.LogError(string.Concat(new object[]
			{
				"subsetSize: ",
				subsetSize,
				" cannot be greater than n: ",
				n
			}));
		}
		int[] array = new int[subsetSize];
		MathUtils.PopulateArray<int>(array, -1);
		for (int i = 0; i < subsetSize; i++)
		{
			int num;
			do
			{
				num = UnityEngine.Random.Range(0, n);
			}
			while (MathUtils.ArrayContainsValueInRange<int>(array, num, 0, i) || (isValueAllowed != null && !isValueAllowed(num)));
			array[i] = num;
		}
		return array;
	}

	public static void PopulateArray<T>(T[] array, T someValue)
	{
		int num = array.Length;
		for (int i = 0; i < num; i++)
		{
			array[i] = someValue;
		}
	}

	public static bool ArrayContainsValueInRange<T>(T[] array, T someValue, int beginIndex, int endIndex)
	{
		for (int i = beginIndex; i < endIndex; i++)
		{
			if (EqualityComparer<T>.Default.Equals(array[i], someValue))
			{
				return true;
			}
		}
		return false;
	}

	public static bool AreRectsIntersecting(Rect r1, Rect r2)
	{
		float num = Mathf.Max(r1.xMin, r2.xMin);
		float num2 = Mathf.Min(r1.xMax, r2.xMax);
		float num3 = Mathf.Max(r1.yMin, r2.yMin);
		float num4 = Mathf.Min(r1.yMax, r2.yMax);
		return num <= num2 && num3 <= num4;
	}

	public const float SQRT_3 = 1.73205078f;

	public const float INV_SQRT_3 = 0.577350259f;

	public const float TRIANGLE_HEIGHT_TO_SIDE = 0.8660254f;

	public delegate bool IsValueAllowed(int val);
}
